<?php
/**
 * 登陆相关操作
 * @author sz 2016-8-31 15:06:52
 * @version 1.0
 */
namespace Home\Controller;

class LoginController extends PmpController
{

    /**
     * 默认首页
     *
     * @author sz 2016-8-31 09:49:12
     * @version 1.0
     */
    public function index ()
    {
        $user_name = $_SESSION['hb_think_name'];
        if ($user_name != null)
        {
            header("Location: " . '?c=index&a=index');
        }
        else
        {
            $this->display();
        }
    }
    
    /**
     * 登录验证和session设置
     *
     * @author sz 2016-8-31 15:20:22
     * @version 1.0
     */
    public function login ()
    {
        $account = $_REQUEST['user_name'];
        $password = $_REQUEST['password'];
        $memberUserModel = D('MemberUser');
        $selFlag = $memberUserModel->checkMember($account);
        if ($selFlag[0]['salt'] == null)
        {
            echo '-9';
        }
        else
        {
            $salt = $selFlag[0]['salt'];
            $edsPassword = md5(md5($password) . $salt);
            $infoArr = $memberUserModel->login($account, $edsPassword);
            if ($infoArr === false)
            {
                echo '0';
            }
            elseif (empty($infoArr) == true)
            {
                echo '-1';
            }
            else
            {
                // 将编辑信息与编辑组信息存入session
                $id = $infoArr[0]['id'];
                session('hb_think_id', $id);
                session('hb_think_group_id', $infoArr[0]['group_id']);
                session('hb_think_name', $infoArr[0]['user_name']);
                session('hb_think_group_name', $infoArr[0]['group_name']);
                $avatar = $infoArr[0]['avatar'];
                if ($avatar == null)
                {
                    $avatar = C('URL_POST') . 'Public/img/slogo.jpg';
                }
                else
                {
                    $avatar = C('URL_ADMIN_POST') . $avatar;
                }
                session('hb_think_avatar', $avatar);
                echo "1";
            }
        }
    }
}